<?php
//
/*	Created by Alexander Alexandrov aka SS

			hazg@mail.ru				*/

define('SSLIB_Template', TRUE);
if(!defined("SSLIB_Html")) die(__FILE__." Html class missing");


/*
 * 
 * TODO: Optimize, check for Err localization
 */
class Template
{
    static $g_sslib_templates = array(); 
	static function CompileFile($arr, $templ, $insertBR = false)
	{
		
		$md5 = $templ;
		if(!array_key_exists($md5, Template::$g_sslib_templates)) 
		{
			if(!is_file($templ))
			{
			    new Err(__T('file not found').": $templ");
			    return;
			}
			else 
			{
			    Template::$g_sslib_templates[$md5] = file_get_contents($templ);
			}
			
		}
		$templ = Template::$g_sslib_templates[$md5];
		return Template::Compile($arr, $templ, $insertBR);
	}
	static function Compile($arr, $templ, $insertBR = false)
	{		
		foreach($arr as $key => $val)
		{
			$templ = str_replace('{' . $key . '}', $val, $templ);
		}
		return Html::Exec($templ, 'template');
	}
}
Template::$g_sslib_templates = array();
?>